home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Alpha ƒ / Tcl / SystemCode / loadLaTeX.tcl < prev    next >
Text File  |  1995-06-17  |  8KB  |  248 lines

  1. #############################################################################
  2. # Install the files that support one of the LaTeX modes.
  3. # The global flag $latexVersion indicates which mode (LaTeX 2.09 or LaTeX2e)
  4. # is currently installed.
  5. #
  6. # Author: Tom Pollard <pollard@cucbs.chem.columbia.edu>
  7. # (updated 4/29/95 for latex.tcl v2.4)
  8. #
  9. proc loadLaTeX {} {
  10.     global HOME latexVersion
  11.     
  12.     set oldWd [pwd]
  13.     cd $HOME
  14.     
  15.     set latex209Dir ":LaTeX:latex 2.09"
  16.     set latex209Files {
  17.             {"latex.tcl" ":Tcl:SystemCode"}
  18.             {"latexMode.tcl" ":Tcl:SystemCode"}
  19.             {"smart.tcl" ":Tcl:SystemCode"}
  20.             {"LaTeX Help" ":Help"}
  21.             {"LaTeX Key Bindings" ":Help"}
  22.     }
  23.  
  24.     set latex2eDir ":LaTeX:latex 2e"
  25.     set latex2eFiles {
  26.             {"latex.tcl" ":Tcl:SystemCode"}
  27.             {"latexEngine.tcl" ":Tcl:SystemCode"}
  28.             {"latexKeys.tcl" ":Tcl:SystemCode"}
  29.             {"latexMacros.tcl" ":Tcl:SystemCode"}
  30.             {"latexMenu.tcl" ":Tcl:SystemCode"}
  31.             {"latexMode.tcl" ":Tcl:SystemCode"}
  32.             {"latexPatches.tcl" ":Tcl:SystemCode"}
  33.             {"latexSmart.tcl" ":Tcl:SystemCode"}
  34.             {"LaTeX Help" ":Help"}
  35.             {"LaTeX Key Bindings" ":Help"}
  36.     }
  37.     set report 0
  38.  
  39.     if {$latexVersion == "2e"} {
  40.         if {[askyesno "Install LaTeX 2.09?"] == "yes"} {
  41.             set report [installFiles $latex209Dir $latex209Files $latex2eDir $latex2eFiles 0 1 TeX]
  42.             if {$report != 0} {
  43. # uncomment these lines if new files are not automatically sourced
  44. #                 alertnote "Now quit and restart Alpha to load LaTeX 2.09 mode"
  45. #                 set latexVersion "2.09"
  46. # and comment out this one
  47.                 alertnote "LaTeX 2.09 support was successfully installed"
  48. #
  49.             } else {
  50.                 alertnote "The installation was cancelled"
  51.             }
  52.         }
  53.     } elseif {$latexVersion == "2.09"} {
  54.         if {[askyesno "Install LaTeX 2e?"] == "yes"} {
  55.             set report [installFiles $latex2eDir $latex2eFiles $latex209Dir $latex209Files 0 1 TeX]
  56.             if {$report != 0} {
  57. # uncomment these lines if new files are not automatically sourced
  58. #                alertnote "Now quit and restart Alpha to load LaTeX2e mode"
  59. #                set latexVersion "2e"
  60. # and comment out this one
  61.                 alertnote "LaTeX2e support was successfully installed"
  62. #
  63.             } else {
  64.                 alertnote "The installation was cancelled"    
  65.             }
  66.         }
  67.     }
  68.     
  69.     if {$report != 0} {
  70.         set timePat {([0-9/]+) ([^:]+):([^:]+):([^:]+) (..)}
  71.         regsub $timePat [join [mtime [now] short]] {\1 \2.\3\5} timestamp
  72.         set fname "$HOME:LaTeX:Install Report $timestamp"
  73.         
  74.         set tmpfid [open $fname "w+"]
  75.         puts $tmpfid $report
  76.         close $tmpfid
  77.     }
  78.     
  79.     cd $oldWd
  80. }
  81.  
  82. ##############################################################################
  83. # Install a list of files from $InstallDir into various destination folders.
  84. #
  85. # Each item of $installList contains a list of two items : a file and its 
  86. # destination directory.  If $backupDir and $backupList are given, then the 
  87. # files from this list are first removed from the indicated directories and 
  88. # saved in $backupDir.  If $deleteOld is 1, then an old file is just
  89. # deleted if the backup directory doesn't exist or if it already contains
  90. # the file; if $overwriteBackups is 1, then old backup files will be
  91. # overwritten ($deleteOld is checked before $overwriteBackups).
  92. #
  93. # If any Tcl source files (.tcl) are installed, then they are also automatically
  94. # sourced and "rebuildTclIndices" is called to update the autoloader index files.
  95. # Author: Tom Pollard <pollard@cucbs.chem.columbia.edu>
  96. #
  97. proc installFiles {installDir installList backupDir backupList 
  98.                    {deleteOld 0} {overwriteBackups 0} {deleteBindings 0}} {
  99.     global HOME
  100.     set script {}
  101.     set report ""
  102.     set askedAlready 0
  103.     set removed {}
  104.     
  105.     set script2 {}
  106.     set report2 ""
  107.     
  108.     if {! [file exists $backupDir] && ! $deleteOld} {
  109.         lappend script [list mkdir $backupDir]
  110.         append report "Created backup directory \"$backupDir\"\n"
  111.     } 
  112.     
  113.     foreach item $backupList {
  114.         set file [lindex $item 0]
  115.         set dir [lindex $item 1]
  116.         
  117.         set frompath ${dir}:${file}
  118.         set topath ${backupDir}:${file}
  119.  
  120.         if {[closeInstallFile $file] == "cancel"} {
  121.             return 0
  122.         }        
  123.         
  124.         if {[file exists $frompath]} {
  125.             if {[file exists $topath]} {
  126.                 if {!$deleteOld && !$overwriteBackups && !$askedAlready} {
  127.                     if {[askyesno "Can I delete old files that are already backed up?"] == "yes"} {
  128.                         set deleteOld 1
  129.                     } elseif {[askyesno "Can I overwrite previous backup files?"] == "yes"} {
  130.                         set overwriteBackups 1
  131.                     }
  132.                     set askedAlready 1
  133.                 }
  134.                 if {$deleteOld} {
  135.                     lappend script [list removeFile $frompath]
  136.                     append report "Deleted old file \"$file\" from folder \"$dir\"\n"
  137.                     lappend removed $frompath
  138.  
  139.                 } elseif {$overwriteBackups} {
  140.                     lappend script [list removeFile $topath]
  141.                     lappend script [list copyFile $frompath $topath]
  142.                     lappend script [list removeFile $frompath]
  143.                     append report "Saved old file \"$file\" in folder \"$backupDir\"\n"
  144.                     lappend removed $frompath
  145.                 
  146.                 } else {
  147.                     message "No files were moved or deleted"
  148.                     return 0
  149.                 }
  150.             } else {
  151.                 lappend script [list copyFile $frompath $topath]
  152.                 lappend script [list removeFile $frompath]
  153.                 append report "Saved old file \"$file\" in folder \"$backupDir\"\n"
  154.                 lappend removed $frompath
  155.             }
  156.         } else {
  157.             append report "-- old file \"$file\" was missing from folder \"$dir\" --\n"
  158.         }
  159.     }
  160.     
  161.     append report "\n"
  162.     
  163.     foreach item $installList {
  164.         set file [lindex $item 0]
  165.         set dir [lindex $item 1]
  166.         set frompath ${installDir}:${file}
  167.         set topath ${dir}:${file}
  168.         
  169.         if {[closeInstallFile $file] == "cancel"} {
  170.             return 0
  171.         }        
  172.  
  173.         if {[file exists $frompath]} {
  174.             if {[file exists $topath] && [lsearch -exact $removed $topath] < 0} {
  175.                 if {[askyesno "Can I overwrite the old copy of $file?"] == "yes"} {
  176.                     lappend script [list removeFile $topath]
  177.                     append report "Deleted old file \"$file\" in folder \"$dir\"\n"
  178.                     lappend removed $topath
  179.                 } else {
  180.                     return 0
  181.                 }
  182.             }
  183.             lappend script [list copyFile $frompath $topath]
  184.             append report "Copied file \"$file\" from folder \"$installDir\" to \"$dir\"\n"
  185.             
  186.             if {[file extension $file] == ".tcl"} {
  187.                 lappend script2 [list uplevel {#0} [list source ${HOME}$topath]]
  188.                 append report2 "Loaded the new file \"$file\"\n"
  189.             }
  190.         } else {
  191.             message "Installation aborted - no files were moved or deleted"
  192.             alertnote "Install file \"$file\" is missing"
  193.             return 0
  194.         }
  195.     }
  196.  
  197.     if {[llength $script2]} {
  198. # comment out these lines to stop automatic sourcing of newly loaded .tcl files
  199. # (_Don't_ change the lines creating $script2, above)
  200.         if {$deleteBindings != 0} {
  201.             lappend script [list deleteModeBindings $deleteBindings]
  202.             append report "\nRemoved the old ${deleteBindings}-mode key bindings\n"
  203.         }
  204.         set script [concat $script $script2]
  205.         append report "\n"
  206.         append report $report2
  207. #
  208.         lappend script [list message "Building SystemCode index╔"]
  209.         lappend script [list auto_mkindex :Tcl:SystemCode *.tcl]
  210.         append report "\nUpdated the auto-loader index files\n"
  211.     }
  212.     
  213. # # Uncomment these lines to get a play-by-play of the installation procedure 
  214. # #
  215. #    new -n "* Install Script *"
  216.     foreach item $script {
  217. #    insertText "$item\n"
  218.         eval $item
  219.     }
  220. #    catch {shrinkWindow 1}
  221. #    setWinInfo dirty 0
  222.     
  223.     new -n "* Installation Report *"
  224.     insertText $report
  225.     catch {shrinkWindow 1}
  226.     setWinInfo dirty 0
  227.     setWinInfo read-only 1
  228.  
  229.     return $report
  230. }
  231.  
  232. proc closeInstallFile {file} {
  233.     if {[lsearch -exact [winNames] $file] >= 0} {
  234.         set reply [askyesno -c "Close file $file before installing?"]
  235.         if {$reply == "yes"} {
  236.             bringToFront $file
  237.             killWindow
  238.         } 
  239.         if {$reply == "cancel" || 
  240.             ($reply == "yes" && [lsearch -exact [winNames] $file] >= 0)} {
  241.             message "No files were moved or deleted"
  242.             return "cancel"
  243.         }
  244.     }
  245.     return ""
  246. }
  247.